// pages/exam/checkResult/checkResult.js
var app = getApp();
var config = require('../../../config.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //获取传入的考试id
    var id = options.examId;
    this.setData({
      examId: id
    });

    
  },

  bindNumInput(e) {
    this.setData({
      inputNumValue: e.detail.value
    })
  },

//根据准考证号码查询成绩
  checkResultByNum:function(){
    var that = this;
    console.log(app.globalData.openid)
    var cardNum = that.data.inputNumValue;
    if (!cardNum){
      wx.showToast({
        title: '请输入手机号',
        icon:"none"
      })
        return;
    }

    wx.request({
      url: config.queryExamResult,
      method: "POST",
      data: {
        examId: that.data.examId,
        phone: cardNum
      },
      success: function (ret) {
        var data = ret.data
        if (data.success == 0) {
          console.log(data);
          var examInfo = data.rows;
          if (examInfo) {
            //存入到Storage中 避免大数量传递问题
            try {
              wx.setStorageSync(config.examResultInfo, examInfo)
              //跳转到成绩页面
              wx.redirectTo({
                url: '../examResult/examResult?fromType=2&examId=' + that.data.examId 
                  + '&&phone=' + cardNum
              })

            } catch (e) {

            }


          }else{
            wx.showToast({
              title: '暂无成绩',
              icon: "none"

            })
          }

        }else{
          wx.showToast({
            title: '暂无成绩',
            icon: "none"

          })
        }
      }
    })

  },

  //查询自己的成绩
  checkResultSelf: function () {
    var that = this;
    console.log(app.globalData.openid)
    wx.request({
      url: config.queryExamResult,
      method: "POST",
      data: {
        examId: that.data.examId,
        openId: app.globalData.openid
      },
      success: function (ret) {
        var data = ret.data
        if (data.success == 0) {
          console.log(data);
          var examInfo = data.rows;
          if (examInfo) {
            //存入到Storage中 避免大数量传递问题
            try {
              wx.setStorageSync(config.examResultInfo, examInfo)
              //跳转到成绩页面
              wx.redirectTo({
                url: '../examResult/examResult?fromType=2&examId=' + that.data.examId+
                  '&mainId=' + app.globalData.openid
              })

            } catch (e) {

            }


          }else{
            wx.showToast({
              title: '暂无您的成绩',
              icon: "none"
              
            })
          }

        }else{
          wx.showToast({
            title: '暂无您的成绩',
            icon: "none"

          })
        }
      }
    })

  },

  //返回首页
  toHomePage:function(){
    //返回上一级页面（delta：返回的页面数，如果 delta 大于现有页面数，则返回到首页，默认值为1）
    wx.navigateBack({
      delta: 100   //默认值是1

    })

  }

  
})